package integer_reversion;

class Test {
    public static void main(String[] args) {
        System.out.println(new Solution().reverse(123));
    }
}

class Solution {
    public int reverse(int x) {
        int res = 0;
        while (x != 0){
            if (res < Integer.MIN_VALUE / 10 || res > Integer.MAX_VALUE / 10){
                return 0;
            }
            int digit = x % 10;
            res = res * 10 + digit;
            x /= 10;
        }

        return res;
    }
}
